package collectionfram;

import java.util.ArrayList;
import java.util.List;

public class ArrayListDemo01 {
    public static void main(String[] args) {
        /*ArrayList dogs = new ArrayList();

        dogs.add(new Dog("dog1"));
        dogs.add(new Dog("dog2"));
        dogs.add(new Dog("dog3"));
        dogs.add(2,new Dog("dog4"));
        dogs.add("dog4");
        System.out.println(dogs.contains("dog4"));
        System.out.println(dogs.size());

        for (int i = 0; i < dogs.size()-1; i++) {
            Dog dog = (Dog) dogs.get(i);
            System.out.println(dog.getName());
        }*/

        ArrayList<Integer> lists = new ArrayList<Integer>();
        lists.add(8);

        lists.add(11);
        lists.set(1,2); //只能改变已存在的数据
//        System.out.println(lists.get(-1));
        for (int i = 0; i < lists.size(); i++) {
            System.out.println(lists.get(i));// 8,2 11被设置成了2
        }

    }
}

class Dog {
    private String name; //构造。。。set、get、。。。toString（）
    public Dog(String newName){
        this.name = newName;
    }
    public Dog(){

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
